package com.example.flower_shop.dto;

import lombok.Data;

import javax.validation.constraints.Min;

@Data
public class PageRequest {
    @Min(value = 1, message = "页码必须大于0")
    private Integer page = 1;

    @Min(value = 1, message = "每页条数必须大于0")
    private Integer size = 10;

    private String sort;

    private String order = "desc";

    public int getOffset() {
        return (page - 1) * size;
    }

    public org.springframework.data.domain.PageRequest toPageRequest() {
        return org.springframework.data.domain.PageRequest.of(page - 1, size);
    }
}